#include "MsgNode.h"
#include"LogicSystem.h"
MsgNode::MsgNode(short max_len):_total_len(max_len),_cur_len(0)
{
	_data = new char[_total_len + 1];
	_data[_total_len] = '\0';
}

MsgNode::~MsgNode()
{
	delete[] _data;
	std::cout << "MsgNode is over"<<std::endl;
}

void MsgNode::Clear()
{
	std::memset(_data, '\0', _total_len);
	_cur_len = 0;
}

RecvNode::RecvNode(short max_len, short msg_id):MsgNode(max_len),_msg_id(msg_id)
{
}

SendNode::SendNode(short max_len, const char* data,short msg_id):MsgNode(max_len+HEAD_TOTAL_LEN),_msg_id(msg_id)
{
	short network_msg_id = boost::asio::detail::socket_ops::host_to_network_short(_msg_id);
	memcpy(_data, &network_msg_id, HEAD_ID_LEN);

	short network_msg_len = boost::asio::detail::socket_ops::host_to_network_short(max_len);
	memcpy(_data+HEAD_ID_LEN, &network_msg_len, HEAD_DATA_LEN);

	memcpy(_data + HEAD_TOTAL_LEN, data, max_len);
}